package main

import . "local/algorithm/util"

func removeNthNodeFromEnd(head *ListNode, k int) *ListNode {
	if head == nil {
		return nil
	}

	p, q := head, head
	for i := 0; i < k; i++ {
		q = q.Next
	}

	if q == nil {
		return p.Next
	}

	for q.Next != nil {
		p = p.Next
		q = q.Next
	}

	p.Next = p.Next.Next
	return head
}
